package org.admanager.mapping.plugin.diagram.part;

import org.admanager.mapping.plugin.diagram.edit.parts.ComponentComponentCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentMappingEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentNameEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentReferenceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentReferenceMappingEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentServiceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ComponentServiceMappingEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.CompositeCompositeCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.CompositeEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.CompositeMappingEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.CompositeNameEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.DocumentRootDocumentRootCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.DocumentRootEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.DocumentRootNameEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponent2EditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentName2EditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentNameEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentPComponentCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentPInnerComponentCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentReference2EditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentReferenceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentService2EditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PComponentServiceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PCompositeEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PCompositeNameEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PCompositePCompositeCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PReferenceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PServiceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PatternEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PatternNameEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.PatternPatternCompartmentEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ReferenceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ReferenceMappingEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.RootMappingEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ServiceEditPart;
import org.admanager.mapping.plugin.diagram.edit.parts.ServiceMappingEditPart;
import org.admanager.soadmanagement.plugin.soadmanagement.RootMapping;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class SOADManagementMetamodelVisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "org.admanager.mapping.plugin.diagram/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (RootMappingEditPart.MODEL_ID.equals(view.getType())) {
				return RootMappingEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return org.admanager.mapping.plugin.diagram.part.SOADManagementMetamodelVisualIDRegistry
				.getVisualID(view.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				SOADManagementMetamodelDiagramEditorPlugin.getInstance()
						.logError(
								"Unable to parse view type as a visualID number: "
										+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return Integer.toString(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
				.getRootMapping().isSuperTypeOf(domainElement.eClass())
				&& isDiagram((RootMapping) domainElement)) {
			return RootMappingEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = org.admanager.mapping.plugin.diagram.part.SOADManagementMetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!RootMappingEditPart.MODEL_ID.equals(containerModelID)
				&& !"soapattern".equals(containerModelID) && !"simplifiedsca".equals(containerModelID)) { //$NON-NLS-1$ //$NON-NLS-2$
			return -1;
		}
		int containerVisualID;
		if (RootMappingEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.admanager.mapping.plugin.diagram.part.SOADManagementMetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = RootMappingEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case RootMappingEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComponentReferenceMapping().isSuperTypeOf(
							domainElement.eClass())) {
				return ComponentReferenceMappingEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComponentServiceMapping().isSuperTypeOf(
							domainElement.eClass())) {
				return ComponentServiceMappingEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getCompositeMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return CompositeMappingEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComponentMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return ComponentMappingEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getServiceMapping().isSuperTypeOf(domainElement.eClass())) {
				return ServiceMappingEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getReferenceMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return ReferenceMappingEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getDocumentRoot().isSuperTypeOf(domainElement.eClass())) {
				return DocumentRootEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPattern().isSuperTypeOf(domainElement.eClass())) {
				return PatternEditPart.VISUAL_ID;
			}
			break;
		case DocumentRootDocumentRootCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComposite().isSuperTypeOf(domainElement.eClass())) {
				return CompositeEditPart.VISUAL_ID;
			}
			break;
		case CompositeCompositeCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComponent().isSuperTypeOf(domainElement.eClass())) {
				return ComponentEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getService().isSuperTypeOf(domainElement.eClass())) {
				return ServiceEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getReference().isSuperTypeOf(domainElement.eClass())) {
				return ReferenceEditPart.VISUAL_ID;
			}
			break;
		case ComponentComponentCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComponentReference().isSuperTypeOf(
							domainElement.eClass())) {
				return ComponentReferenceEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getComponentService()
					.isSuperTypeOf(domainElement.eClass())) {
				return ComponentServiceEditPart.VISUAL_ID;
			}
			break;
		case PatternPatternCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComponent().isSuperTypeOf(domainElement.eClass())) {
				return PComponentEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComposite().isSuperTypeOf(domainElement.eClass())) {
				return PCompositeEditPart.VISUAL_ID;
			}
			break;
		case PComponentPComponentCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComponentService().isSuperTypeOf(
							domainElement.eClass())) {
				return PComponentServiceEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComponentReference().isSuperTypeOf(
							domainElement.eClass())) {
				return PComponentReferenceEditPart.VISUAL_ID;
			}
			break;
		case PCompositePCompositeCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComponent().isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPService().isSuperTypeOf(domainElement.eClass())) {
				return PServiceEditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPReference().isSuperTypeOf(domainElement.eClass())) {
				return PReferenceEditPart.VISUAL_ID;
			}
			break;
		case PComponentPInnerComponentCompartmentEditPart.VISUAL_ID:
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComponentService().isSuperTypeOf(
							domainElement.eClass())) {
				return PComponentService2EditPart.VISUAL_ID;
			}
			if (org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
					.getPComponentReference().isSuperTypeOf(
							domainElement.eClass())) {
				return PComponentReference2EditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = org.admanager.mapping.plugin.diagram.part.SOADManagementMetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!RootMappingEditPart.MODEL_ID.equals(containerModelID)
				&& !"soapattern".equals(containerModelID) && !"simplifiedsca".equals(containerModelID)) { //$NON-NLS-1$ //$NON-NLS-2$
			return false;
		}
		int containerVisualID;
		if (RootMappingEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.admanager.mapping.plugin.diagram.part.SOADManagementMetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = RootMappingEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case RootMappingEditPart.VISUAL_ID:
			if (ComponentReferenceMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComponentServiceMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (CompositeMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComponentMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ServiceMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ReferenceMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DocumentRootEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PatternEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DocumentRootEditPart.VISUAL_ID:
			if (DocumentRootNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DocumentRootDocumentRootCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PatternEditPart.VISUAL_ID:
			if (PatternNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PatternPatternCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case CompositeEditPart.VISUAL_ID:
			if (CompositeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (CompositeCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ComponentEditPart.VISUAL_ID:
			if (ComponentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComponentComponentCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentEditPart.VISUAL_ID:
			if (PComponentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPComponentCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PCompositeEditPart.VISUAL_ID:
			if (PCompositeNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PCompositePCompositeCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponent2EditPart.VISUAL_ID:
			if (PComponentName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPInnerComponentCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DocumentRootDocumentRootCompartmentEditPart.VISUAL_ID:
			if (CompositeEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case CompositeCompositeCompartmentEditPart.VISUAL_ID:
			if (ComponentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ServiceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ReferenceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ComponentComponentCompartmentEditPart.VISUAL_ID:
			if (ComponentReferenceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComponentServiceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PatternPatternCompartmentEditPart.VISUAL_ID:
			if (PComponentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PCompositeEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentPComponentCompartmentEditPart.VISUAL_ID:
			if (PComponentServiceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentReferenceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PCompositePCompositeCompartmentEditPart.VISUAL_ID:
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PServiceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PReferenceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentPInnerComponentCompartmentEditPart.VISUAL_ID:
			if (PComponentService2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentReference2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(RootMapping element) {
		return true;
	}

}
